<script>
import Vue from "vue";
import { getTIMUserID } from "./utils/tim/helper";
import initTim from "./utils/tim/initTim";

export default {
	globalData: {
		unReadCount: 0,
		baseUrl: 'https://api.yijiangongxiang.com/',
		houserId: '',
		swiperList: [],
		messageRefresh: false,
		selectDate: false,
		// sellerHead: 'https://image-test.xtrip.com/content/20220321/a9d9536608ef5e8018a5f72bf47b35f2.png',
		shareTitle: '薪岗通',
		sexList: [
			{ label: '男', value: 0 },
			{ label: '女', value: 1 },
		],
		// 学历要求
		education: [
			{ label: '初中', value: 1 },
			{ label: '中专/中技', value: 7 },
			{ label: '高中', value: 2 },
			{ label: '大专', value: 3 },
			{ label: '本科', value: 4 },
			{ label: '硕士', value: 5 },
			{ label: '博士', value: 6 },
		],
		// 经验要求
		experience: [
			{ label: '在校/应届', value: 1 },
			{ label: '近期毕业', value: 2 },
			{ label: '1年以内', value: 3 },
			{ label: '1-3年', value: 4 },
			{ label: '3-5年', value: 5 },
			{ label: '5-10年', value: 6 },
			{ label: '10年以上', value: 7 }
		],
		// 薪资待遇
		PriceList: [
			{ label: '3K以下', value: 1 },
			{ label: '3-5K', value: 2 },
			{ label: '5-10K', value: 3 },
			{ label: '10-20K', value: 4 },
			{ label: '20-50K', value: 5 },
			{ label: '50K以上', value: 6 }
		],
		// 公司规模
		comPeople: [
			{ label: '0-20人', value: 1 },
			{ label: '20-99人', value: 2 },
			{ label: '100-499人', value: 3 },
			{ label: '500-999人', value: 4 },
			{ label: '1000-9999人', value: 5 },
			{ label: '10000人以上', value: 6 }
		],
		// 求职状态
		jobSeek: [
			{ label: '离职-随时到岗', value: 1 },
			{ label: '在职-月内到岗', value: 2 },
			{ label: '在职-考虑机会', value: 3 },
			{ label: '在职-暂不考虑', value: 4 }
		],
		positionType: [
			{ label: '社招全职', value: 1, label2: '全职' },
			{ label: '应届校园招聘', value: 2, label2: '应届生' },
			{ label: '实习生招聘', value: 3, label2: '实习生' },
			{ label: '兼职招聘', value: 4, label2: '兼职' }
		],
		upload: 'common/upload'

	},
	onLaunch: async function () {
		const updateManager = uni.getUpdateManager();

		updateManager.onCheckForUpdate(function (res) {
			// 请求完新版本信息的回调
			console.log(res.hasUpdate);
		});
		updateManager.onUpdateReady(function (res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});
		});
		updateManager.onUpdateFailed(function (res) {
			// 新的版本下载失败
		});
		let that = this;
		uni.hideTabBar()
		this.$p.getShare()
		uni.getPrivacySetting({
			success(res) {
				console.log('是否需要授权：', res.needAuthorization, '隐私协议的名称为：', res.privacyContractName);
				if (res.needAuthorization) {
					that.globalData.privacyContractName = res.privacyContractName;
					that.globalData.showPrivacy = true;
				} else {
					that.globalData.showPrivacy = false;
				}
			}
		});

		// 微信登录
		uni.login({
			success: async (res) => {
				uni.setStorageSync("code", res.code);
				// const {
				// 	data: {
				// 		openId,
				// 		sessionKey
				// 	},
				// } = await getSessionKey({
				// 	code: res.code,
				// });
				// uni.setStorageSync("openId", openId);
				// uni.setStorageSync("sessionKey", sessionKey);
			},
		});
		function storageMobileInfo(res) {
			if (res.system.indexOf("iOS") == -1) {
				if (res.brand == 'samsung' || res.brand == 'HONOR') {
					uni.setStorageSync("brandModel", "三星");
				}
				uni.setStorageSync("system", "android");
			} else {
				uni.setStorageSync("system", "ios");
			}
		}
		var systemInfo = uni.getSystemInfoSync();
		storageMobileInfo(systemInfo);
		// #ifndef MP
		Vue.prototype.StatusBar = systemInfo.statusBarHeight;
		if (e.platform == "android") {
			Vue.prototype.CustomBar = systemInfo.statusBarHeight + 50;
		} else {
			Vue.prototype.CustomBar = systemInfo.statusBarHeight + 45;
		}
		// #endif
		// #ifdef MP-WEIXIN
		Vue.prototype.StatusBar = systemInfo.statusBarHeight;
		let custom = wx.getMenuButtonBoundingClientRect(); //ios 有问题
		Vue.prototype.Custom = custom;
		Vue.prototype.CustomBar =
			(88 * systemInfo.windowWidth) / 750 + systemInfo.statusBarHeight;
		// #endif
		Vue.prototype.windowWidth = systemInfo.windowWidth;
		Vue.prototype.$chat = initTim();
	},

	onShow: function () {
		uni.hideTabBar()
	},
	computed: {
		userInfo() {
			return this.$store.state.user.userInfo;
		},
		isReady() {
			return this.$store.state.tim.isReady;
		},
	},
	watch: {
		userInfo: {
			handler(value, oldValue) {
				if (value?.userId && value?.userId !== oldValue?.userId) {
					this.loginTim(value)
				}
			},
			immediate: true,
			deep: true
		}
	},
	methods: {
		// 登录 & 更新用户信息
		loginTim() {
			this.$nextTick(() => {
				const _userID = getTIMUserID(this.userInfo.userId, this.userInfo.userType)
				console.log('userInfo.userId--->', this.userInfo.userId, _userID)
				if (Vue.prototype.$chat) {
					if (this.isReady) {
						Vue.prototype.$chat.logout()
					}
					Vue.prototype.$chat.login(_userID)
				}
			});
		}
	}
};
</script>
<style lang="scss">
/*每个页面公共css */
@import "@/uni_modules/uview-ui/index.scss";
//@import "colorui/icon.css";
@import "colorui/main.css";
// @import "colorui/animation.css";
@import "main.scss";
@import "static/iconfont/iconfont.css";
@import "pages/chatroom/MessageList/MessageList.scss";

@for $i from 1 through 250 {
	.lh-#{$i} {
		line-height: $i+rpx !important;
	}

	.h-#{$i} {
		height: $i+rpx !important;
	}

	.r-#{$i} {
		right: $i + rpx !important;
	}

	.t-#{$i} {
		top: $i+rpx !important;
	}

	.mt-#{$i} {
		margin-top: $i + rpx !important;
	}

	.mb-#{$i} {
		margin-bottom: $i + rpx !important;
	}

	.ml-#{$i} {
		margin-left: $i + rpx !important;
	}

	.mr-#{$i} {
		margin-right: $i + rpx !important;
	}

	.pt-#{$i} {
		padding-top: $i + rpx !important;
	}

	.p-#{$i} {
		padding: $i + rpx !important;
	}

	.m-#{$i} {
		margin: $i + rpx !important;
	}

	.pb-#{$i} {
		padding-bottom: $i + rpx !important;
	}

	.pl-#{$i} {
		padding-left: $i + rpx !important;
	}

	.pr-#{$i} {
		padding-right: $i + rpx !important;
	}
}

// 定义字体大小
@for $i from 1 through 200 {
	.fontS#{$i} {
		font-size: $i + rpx !important;
	}

	.img-#{$i} {
		width: $i + rpx !important;
		height: $i + rpx !important;
		min-width: $i + rpx !important;
	}

	.h#{$i} {

		height: $i + rpx !important;
	}
}

.upload-tip {
	margin: 20rpx 0 40rpx 0;
	text-align: center;
	font-size: 24rpx;
	color: #666;
	width: 100%;
}

.cancle {
	background: #fff;
	border-radius: 20rpx;
	height: 104rpx;
	line-height: 104rpx;
	margin: 16rpx 16rpx 32rpx;
	text-align: center;
	font-size: 32rpx;
	color: #222;
}

.bottom-opration {
	margin: 16rpx;
	background: #fff;
	width: calc(100% - 32rpx);
	border-radius: 20rpx;

	view {
		font-size: PingFangSC-Regular, PingFang SC;
		height: 104rpx;
		line-height: 104rpx;
		font-size: 32rpx;
		color: #222;
		text-align: center;
		border-bottom: 1px solid #efefef;
	}

	view:last-child {
		border-bottom: none;
	}
}

.commentModels {
	box-shadow: 0px 0px 20px 0px rgba(187, 187, 187, 0.15);
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	// height: 172rpx;
	background: #fff;
	z-index: 20;
	padding: 40rpx 32rpx;
	display: flex;

	input {
		border: 1px solid #f7f7f7;
		padding: 16rpx;
		width: 100%;
		background: #f7f7f7;
		border-radius: 16rpx;
		line-height: 36rpx;
		font-size: 28rpx;
		height: 88rpx;
		color: #999;
		word-break: break-all;
	}

	div {
		margin-left: auto;
		justify-content: flex-end;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-radius: 60rpx;
		color: #fff;
		height: 140rpx;
		line-height: 140rpx;

		image {
			width: 36rpx;
			height: 36rpx;
			margin: 0 24rpx;
		}

		div {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #ff595f;
		}
	}
}

.textareaBorder {
	border-color: #ff595f !important;
}

.fontE11 {
	// display: -webkit-box;
	white-space: normal !important;
	word-break: break-all !important;
	overflow: hidden !important;
	-webkit-line-clamp: 1 !important;
	text-overflow: ellipsis !important;
}

.fontE1 {
	// display: -webkit-box;
	white-space: nowrap !important;
	word-break: break-all !important;
	overflow: hidden !important;
	-webkit-line-clamp: 1 !important;
	text-overflow: ellipsis !important;
}

.fontE2 {
	display: -webkit-box;
	word-break: break-all;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2 !important;
	overflow: hidden;
	text-overflow: ellipsis;
}

.fontE3 {
	display: -webkit-box;
	word-break: break-all;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3 !important;
	overflow: hidden;
	text-overflow: ellipsis;
}

.flexHC {
	display: flex;
	align-items: center;
}

.flexH {
	display: flex;
}

.flexHBC {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.placeholder-class {
	color: #999 !important;
}

page {
	background: #f7f7f7;
	font-family: PingFangSC-Regular;
}

button {
	margin: 0;
	padding: 0;
	background: none;
	line-height: 1;

	&.button-hover {
		background: initial;
		color: initial;
	}
}

button::after {
	display: none;
	background: none;
}

img,
image {
	display: flex;
}

view,
text,
image,
icon {
	box-sizing: border-box;
}

.bottomLogo {
	width: 270rpx;
	height: 80rpx;
	margin: 0 auto;
}

.with-tabbar {
	padding-bottom: var(--tabbar-height, 92px) !important;
}
</style>
